package com.platform.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.platform.entity.EnergySpcEntity;
import com.platform.service.EnergySpcService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import sun.security.krb5.internal.PAData;

/**
 * SPC记录表Controller
 *
 * @author liweihai
 * @email liweihai12345@sina.com
 * @date 2019-05-25 23:38:11
 */
@RestController
@RequestMapping("energyspc")
public class EnergySpcController {
    @Autowired
    private EnergySpcService energySpcService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("energyspc:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<EnergySpcEntity> energySpcList = energySpcService.queryList(query);
        int total = energySpcService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(energySpcList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("energyspc:info")
    public R info(@PathVariable("id") Long id) {
        EnergySpcEntity energySpc = energySpcService.queryObject(id);

        return R.ok().put("energySpc", energySpc);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("energyspc:save")
    public R save(@RequestBody EnergySpcEntity energySpc) {
        energySpcService.save(energySpc);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("energyspc:update")
    public R update(@RequestBody EnergySpcEntity energySpc) {
        energySpcService.update(energySpc);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("energyspc:delete")
    public R delete(@RequestBody Long[] ids) {
        energySpcService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<EnergySpcEntity> list = energySpcService.queryList(params);

        return R.ok().put("list", list);
    }


    /**
     * 查看游戏收入支出
     * @param params
     * @return
     */
    @RequestMapping("/queryGameDetails")
    public R queryGameDetails(@RequestBody Map<String,Object> params){
//        System.out.println(JSONObject.toJSONString(params));
        if(params.get("type")==null||params.get("type").equals("")){
            Map<String,Object> param = energySpcService.queryWagerCount(params);
            Map<String,Object> param2 = energySpcService.queryWagerCount(params);
            Map<String,Object> result = new HashMap<String, Object>();
            result.put("totalSpend",new BigDecimal(param.get("totalSpend").toString()).add(new BigDecimal(param2.get("totalSpend").toString())));
            result.put("totalPrice",new BigDecimal(param.get("totalPrice").toString()).add(new BigDecimal(param2.get("totalPrice").toString())));
            return R.ok().put("model",result);
        }else{
            if(params.get("type").equals("5")){
                Map<String,Object> param = energySpcService.queryWagerCount(params);
                return R.ok().put("model",param);
            }else{

                Map<String,Object> param = energySpcService.queryRecordCount(params);
                return R.ok().put("model",param);
            }
        }


    }
}
